package com.example.servlet;

import com.example.entity.customerAdmin.ContactUser;
import com.example.service.ContactService;
import com.example.utils.BaseServlet;
import com.example.utils.ResultData;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/contact")
public class ContactServlet extends BaseServlet {
    ContactService contactService=new ContactService();
    @Override
    public Class getChildClass() {
        return this.getClass();
    }
    public ResultData selectAll(HttpServletRequest request, HttpServletResponse response){
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        return contactService.selectAll(page,limit);
    }
    public ResultData deleteById(HttpServletRequest request,HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
         return contactService.deleteById(id);
    }
    public ResultData addContact(HttpServletRequest request,HttpServletResponse response){
        String name = request.getParameter("concatName");
        int sex = Integer.parseInt(request.getParameter("sex"));
        String role = request.getParameter("role");
        String dept = request.getParameter("dept");
        String phone = request.getParameter("phone");
        String fixPhone = request.getParameter("fixedPhone");
        String email = request.getParameter("email");
        String qq = request.getParameter("qq");
        String address = request.getParameter("address");
        String concatPhone = request.getParameter("concatPhone");
        ContactUser contactUser=new ContactUser();
        contactUser.setName(name);
        contactUser.setSex(sex);
        contactUser.setRole(role);
        contactUser.setDeptJob(dept);
        contactUser.setPhone(phone);
        contactUser.setFixedPhone(fixPhone);
        contactUser.setEmail(email);
        contactUser.setQq(qq);
        contactUser.setAddress(address);
        contactUser.setTransPhone(concatPhone);
        return contactService.addContact(contactUser);
    }
    public ResultData selectConRecord(HttpServletRequest request,HttpServletResponse response){
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        return contactService.selectConRecord(page,limit);
    }
}
